var MutiReport = {
	pages : [],
	inited : false,
	PAGE_NAME : "page",
	pageSize : 0,
	currentIndex : 0,
	maxLen : 300,
	pattern : /^page(\d){1,3}$/,
	pageLabel : null,
	pageContainer : null,
	checkInit : function() {
		if (! MutiReport.inited) {
			MutiReport.init();
		}
	},
	setPageContainer : function(id) {
		//checkInit();
		MutiReport.pageContainer = document.getElementById(id);
	},

	init : function(containerId) {
		if (containerId) {
			MutiReport.setPageContainer(containerId);
		}
		MutiReport.pages = MutiReport.getPages();
		MutiReport.currentIndex = 0;
		MutiReport.inited = true;
		MutiReport.pageLabel = document.getElementById('pageLabel');
	},
	
	getPages : function() {
		if (! MutiReport.pageContainer) {
			MutiReport.pageContainer = document.body;
		}
		var pagelist = [];
		MutiReport.pageSize = 0;
		for (var i = 1; i <= MutiReport.maxLen; i++) {
			var tempPage = document.getElementById(MutiReport.PAGE_NAME + i);
			if (tempPage != null && tempPage.id) {
				pagelist.push(tempPage);
				MutiReport.pageSize ++;
			}
		}
		return pagelist;
	},
	
	hideAllPages : function() {
		MutiReport.checkInit();
		for (var i = 0; i < MutiReport.pages.length; i++) {			
			MutiReport.pages[i].className="page_hidden";
		}
	},
	showPage : function(page) {
		MutiReport.checkInit();
		page.className="page_show";
	},
	switchPage : function(index) {
		MutiReport.checkInit();
		MutiReport.hideAllPages();
		MutiReport.showPage(MutiReport.pages[index]);
		if(MutiReport.pageLabel){
			MutiReport.pageLabel.innerHTML=MutiReport.getPageLabel();
		}
	},
	nextPage : function() {
		MutiReport.checkInit();
		if (MutiReport.currentIndex < MutiReport.pageSize - 1) {
			MutiReport.currentIndex ++;
		}
		MutiReport.switchPage(MutiReport.currentIndex);
	},
	prevPage : function() {
		MutiReport.checkInit();
		if (MutiReport.currentIndex > 0) {
			MutiReport.currentIndex --;
			MutiReport.switchPage(MutiReport.currentIndex);
		}
	},
	firstPage : function() {
		MutiReport.checkInit();
		MutiReport.currentIndex = 0;
		MutiReport.switchPage(MutiReport.currentIndex);
	},
	lastPage : function() {
		MutiReport.checkInit();
		MutiReport.currentIndex = MutiReport.pageSize - 1;
		MutiReport.switchPage(MutiReport.currentIndex);
	},
	
	isFirstPage : function() {
		MutiReport.checkInit();
		return MutiReport.currentIndex == 0;
	},
	isLastPage : function() {
		MutiReport.checkInit();
		return MutiReport.currentIndex == (MutiReport.pageSize - 1);
	},
	getPageLabel : function() {
		MutiReport.checkInit();
		return (MutiReport.currentIndex + 1) + "/" + MutiReport.pageSize;
	}
};